<template>
<div class="merchandise-categories-add views-container" v-loading="loading">
    <el-dialog width="45%" :visible.sync="dialogListVisible" @close="clearData" custom-class="reset-pwd wlm-form-dialog dialog-table" style="margin-top: -10vh;">
        <div class="wlm-form" v-if="dialogListVisible" style="margin-bottom:0">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">{{formType=='1'?'商家列表':'门店列表'}}</span>
            </div>
            <!-- <el-scrollbar wrap-class="scrollbar-wrapper"> -->
            <div class="wlm-table-header" style="margin-bottom:-20px;margin-top:14px;">
                <el-form :model="tableFormatData.userTable.files" size="small" label-width="110px" class="retail-form" label-position="right">
                    <el-form-item label="" class="filter" label-width="10px">
                        <el-form-item class="search">
                            <el-input v-model="tableFormatData.userTable.files.name" placeholder="请输入名称" style="width:200px;margin-left:25px;"></el-input>
                            <el-button style="margin-left:10px;" type="primary" @click="filesSerch">搜索</el-button>
                        </el-form-item>
                    </el-form-item>
                </el-form>
            </div>
            <el-table :row-class-name="tableRowClassName" v-loading="!isTableFormatGetEnd" v-if="formType=='1'" class="chooseTable" :data="tableFormatData.userTable.tableData" :row-style="{cursor:'pointer'}" @row-click="merchantRowClick" highlight-current-row style="width: 100%;padding:0 30px;border-bottom:none">
                <el-table-column prop="date" label="商家名称">
                    <template slot-scope="scope">
                        <p>{{scope.row.name}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="门店数量">
                    <template slot-scope="scope">
                        <p>{{scope.row.storenum}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="成为时间">
                    <template slot-scope="scope">
                        <p>{{scope.row.create_time}}</p>
                    </template>
                </el-table-column>
            </el-table>
            <el-table ref="multipleTable" v-loading="!isTableFormatGetEnd" v-if="formType=='2'" class="chooseTable" @selection-change="storeChange" :data="tableFormatData.userTable.tableData" style="width: 100%;padding:0 30px;border-bottom:none">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="门店名称">
                    <template slot-scope="scope">
                        <p>{{scope.row.name}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="店员数量">
                    <template slot-scope="scope">
                        <p>{{scope.row.menum}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="成为时间">
                    <template slot-scope="scope">
                        <p>{{scope.row.create_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c" style="padding-right: 20px;height:60px;">
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
            <!-- </el-scrollbar> -->
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" type="primary" @click="dialogListVisible = false">确定</el-button>
        </footer>
    </el-dialog>

    <div class="wlm-form">
        <div class="wlm-form-header">基本设置</div>
        <div class="wlm-form-content">
            <el-form ref="basicset" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="200px" class="retail-form" label-position="right">
                <el-form-item label="活动名称" prop="title">
                    <el-input v-model.trim="formFormatData.formData.title"></el-input>
                </el-form-item>
                <el-form-item label="活动时间" :required="true">
                    <el-date-picker :disabled="status==1" :picker-options="pickerOptions" style="width:360px;" :default-time="[`${new Date().getHours()}:${(new Date().getMinutes() + 5).toString().padStart(2,'0')}:00`,'23:59:59']" v-model="formFormatData.formData.time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                      
                </el-form-item>
                <el-form-item label="活动渠道" prop="source" :required="true">
                    <el-checkbox-group v-model="formFormatData.formData.source">
                        <el-checkbox label="2" v-if="JSON.stringify($store.getters.power).indexOf('wxapp')>-1">微信小程序</el-checkbox>
                        <el-checkbox label="3" v-if="JSON.stringify($store.getters.power).indexOf('H5')>-1">H5</el-checkbox>
                        <el-checkbox label="4" v-if="JSON.stringify($store.getters.power).indexOf('wechat')>-1">微信公众号</el-checkbox>
                        <!--  <el-checkbox label="7" v-if="JSON.stringify($store.getters.power).indexOf('aliapp')>-1">支付宝小程序</el-checkbox>
                                    <el-checkbox label="9" v-if="JSON.stringify($store.getters.power).indexOf('toutiaoapp')>-1">抖音-头条</el-checkbox> -->
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="主题背景颜色" prop="time">
                    <el-color-picker v-model="formFormatData.formData.background_color"></el-color-picker>
                </el-form-item>
                <el-form-item label="背景音乐" prop="time">
                    <choose-files ref="chooseFiles" :config="choosePlatmaginConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                </el-form-item>
                <el-form-item label="活动主图" :required="true">
                    <choose-files ref="chooseFiles" :config="choosePlatformConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">建议尺寸：400*400像素</div>
                </el-form-item>
                <el-form-item label="小程序分享图" :required="true">
                    <choose-files ref="chooseFiles" :config="choosePlatsappConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">建议尺寸：500*400像素</div>
                </el-form-item>
                <el-form-item label="公众号分享图" :required="true">
                    <choose-files ref="chooseFiles" :config="choosePlatwechatConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">建议尺寸：100*100像素</div>
                </el-form-item>
                <el-form-item label="分享描述" :required="true">
                    <!-- <el-input v-model.trim="formFormatData.formData.blessing_wechat_text">
                    </el-input> -->
                       <el-input
                        type="textarea"
                        :rows="5"
                        placeholder="请输入分享描述"
                        style="width:55%"
                         v-model.trim="formFormatData.formData.blessing_wechat_text">
                        </el-input>
                </el-form-item>
                <el-form-item label="是否开启虚拟浏览量" prop="time">
                            <el-radio-group v-model="formFormatData.formData.is_false_look">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                         <el-form-item label="随机增加虚拟浏览量" prop="time" v-if="formFormatData.formData.is_false_look==1">
                            <el-input  v-model.trim="formFormatData.formData.false_look_rand" >
                            </el-input>
                            <div class="form-help">格式1|10随机最小值|随机最大值，0为不设置浏览量</div>
                        </el-form-item>
                         <el-form-item label="虚拟基础浏览量" prop="time" v-if="formFormatData.formData.is_false_look==1">
                            <el-input-number  v-model.trim="formFormatData.formData.false_look_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                         <el-form-item label="是否开启虚拟求助量" prop="time">
                            <el-radio-group v-model="formFormatData.formData.is_false_forward">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                         <el-form-item label="随机增加虚拟求助量" prop="time" v-if="formFormatData.formData.is_false_forward==1">
                            <el-input  v-model.trim="formFormatData.formData.false_forward_rand" >
                            </el-input>
                            <div class="form-help">格式1|10随机最小值|随机最大值，0为不设置求助量</div>
                        </el-form-item>
                         <el-form-item label="虚拟基础求助量" prop="time" v-if="formFormatData.formData.is_false_forward==1">
                            <el-input-number  v-model.trim="formFormatData.formData.false_forward_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                         <el-form-item label="虚拟人数" prop="time" >
                            <!-- <el-input  v-model.trim="formFormatData.formData.false_user_num">
                            </el-input> -->
                              <el-input-number  v-model.trim="formFormatData.formData.false_user_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                <el-form-item label="搭配商品">
                    <choose-goods ref="chooseGoods" :config="chooseGoodsConfig" :changeEvt="filtersChange"></choose-goods>
                    <el-button type="primary" @click="goodsToogle">选择商品</el-button>
                    <div style="height:10px;"></div>
                    <el-table v-if="formFormatData.formData.goods != ''" :data="formFormatData.formData.goods" style="width: 100%;">
                        <el-table-column label="商品">
                            <template slot-scope="scope">
                                <div class="flex-row">
                                    <!-- {{scope.row.}} -->
                                    <img class="logo" v-if="scope.row.goods.image && scope.row.goods.image" :src="scope.row.goods.image[0]['file_path']">
                                    <!-- <img class="logo" :src="scope.row.goods.image[0]['file_path']"> -->
                                    <div class="inner-text">
                                        <p>{{scope.row.goods.goods_name}}</p>
                                    </div>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <div class="operation-group">
                                    <el-button class="wlm-text" type="text" @click="deleteTable(scope)">删除</el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>
                <el-form-item label="是否强制关注公众号">
                    <el-radio-group v-model="formFormatData.formData.is_subscribe">
                        <el-radio :label="1">是</el-radio>
                        <el-radio :label="2">否</el-radio>
                    </el-radio-group>
                </el-form-item>
                <!-- <el-form-item label="虚拟浏览量" prop="time">
                    <el-input-number v-model.trim="formFormatData.formData.false_look_num" :controls="false">
                    </el-input-number>
                </el-form-item> -->
                <el-form-item label="参与人群" :required="true">
                    <el-radio-group v-model="formFormatData.formData.user_group">
                        <el-radio :label="1">所有用户可参与</el-radio>
                        <el-radio :label="2">仅会员可参与</el-radio>
                        <el-radio :label="3">分销用户</el-radio>
                        <el-radio :label="4">新用户</el-radio>
                        <el-radio :label="5">限定地区用户</el-radio>
                        <el-radio :label="6">标签用户</el-radio>
                        <el-select v-model="formFormatData.formData.label_ids" multiple placeholder="请选择标签用户" collapse-tags v-if="formFormatData.formData.user_group==6">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value.toString()"></el-option>
                        </el-select>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="地区信息" v-if="formFormatData.formData.user_group=='5'" prop="address">
                    <el-input v-model.trim="formFormatData.formData.address">
                    </el-input>
                    <p class="form-help">如果您希望仅限成都和重庆地区的用户参加抽奖，则填入成都、重庆，地区仅限市级地区</p>
                </el-form-item>
                <el-form-item label="选择社群">
                    <el-select v-model="formFormatData.formData.community" multiple placeholder="请选择社群" style="width:200px;">
                        <el-option v-for="item in selectValue" :key="item.id" :label="item.title" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="参与用户打标签" prop="address">
                    <el-select v-model="formFormatData.formData.label" multiple placeholder="请选择">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                  <el-form-item label="活动规则">
                    <el-input
                        type="textarea"
                        :rows="2"
                        placeholder="请输入内容"
                       v-model="formFormatData.formData.blessing_rule" style="width:50%;">
                        </el-input>
                </el-form-item>
                <el-form-item label="活动内容" :required="true">
                    <ueditor v-if="isFirst" :ueditorChange="shopInfoChange" :ueditorList="ueditorList" :bindIndex="1" :defaultMsg='defaultMsg1' :config='{initialFrameWidth: null,initialFrameHeight: 350}' ref="by_know"></ueditor>
                </el-form-item>
                
            </el-form>
        </div>
    </div>
    <div class="wlm-form">
        <div class="wlm-form-header">奖品/中奖设置</div>
        <div class="wlm-form-content">
            <el-form ref="active" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="220px" class="retail-form" label-position="right">
                <el-form-item label="用户每天抽奖次数" :required="true">
                    <el-input-number :controls="false" v-model="formFormatData.formData.draw_count_day">
                    </el-input-number>
                </el-form-item>
                <el-form-item label="分享可得抽奖次数" :required="true">
                    <el-input-number :controls="false" v-model="formFormatData.formData.share_draw_count">
                    </el-input-number>
                    <div class="form-help">用户成功求助一次后可得抽奖次数</div>
                </el-form-item>
                <el-form-item label="每天分享最多得抽奖次数" :required="true">
                    <el-input-number :controls="false" v-model="formFormatData.formData.share_draw_impose">
                    </el-input-number>
                    <div class="form-help">用户成功求助最多可得抽奖次数</div>
                </el-form-item>
                <el-form-item label="奖品名称" :required="true">
                    <el-input  v-model="formFormatData.formData.prize.title">
                    </el-input>
                </el-form-item>
                <el-form-item label="奖品价值" :required="true">
                    <el-input-number :controls="false" v-model.trim="formFormatData.formData.prize_price">
                    </el-input-number>
                </el-form-item>

                <el-form-item label="选择核销商家" :required="true">
                    <el-button style="max-width:200px;" plain @click="showDialogSet()">
                        <p style="white-space: normal;">{{chooseShangJia}}</p>
                    </el-button>
                </el-form-item>
                <el-form-item label="选择核销门店" :required="true">
                    <el-button style="max-width:200px;" plain @click="showDialogSetDoor()" :disabled="chooseShangJia=='选择商家'">
                        <p style="max-width:200px;white-space: normal;">
                            <span v-if="formFormatData.formData.prize.store_ids == undefined || formFormatData.formData.prize.store_ids.length == 0">选择门店</span>
                            <span v-for="(item, index) in formFormatData.formData.prize.store_ids" :key="index">{{item.name}} {{formFormatData.formData.prize.store_ids != undefined&&formFormatData.formData.prize.store_ids.length>1 && index != formFormatData.formData.prize.store_ids.length-1?'/':''}}</span>
                        </p>
                    </el-button>
                </el-form-item>
                <el-form-item label="奖品数量" :required="true">
                    <el-input-number :controls="false" v-model.trim="formFormatData.formData.prize.prize_num">
                    </el-input-number>
                </el-form-item>
                <el-form-item label="奖品图片" :required="true">
                    <choose-files ref="chooseFiles" :config="chooseimgJp" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">建议尺寸：100*100像素</div>
                </el-form-item>
                <el-form-item label="获奖用户是否可以继续抽奖" :required="true">
                    <el-radio-group v-model="formFormatData.formData.is_win_user_draw">
                        <el-radio :label="1">是</el-radio>
                        <el-radio :label="2">否</el-radio>
                    </el-radio-group>
                    <div class="form-help">配合福袋转赠使用</div>
                </el-form-item>
                <!-- {{$route.query.blessing_id}} -->
                <el-form-item label="奖品发放完是否自动结束活动" :required="true" >
                    <el-radio-group v-model="formFormatData.formData.is_self_close" :disabled="!!$route.query.blessing_id">
                        <el-radio :label="1">是</el-radio>
                        <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="奖品核销有效期" :required="true">
                    <el-radio-group v-model="formFormatData.formData.prize.prize_hx_time_over">
                        <el-radio :label="1">永久</el-radio>
                        <el-radio :label="2">有效时间起
                            <el-input-number v-model="formFormatData.formData.prize.prize_hx_time" :controls="false" class="distribution_type_fenxiao60" style="width:60px;" :min="1" :step="1" step-strictly></el-input-number>天内可使用
                        </el-radio>
                        <el-radio :label="3">
                            <el-date-picker :picker-options="pickerOptions" style="width:360px;" :default-time="[`${new Date().getHours()}:${(new Date().getMinutes() + 5).toString().padStart(2,'0')}:00`,'23:59:59']" v-model="hx_time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                            </el-date-picker>
                        </el-radio>
                    </el-radio-group>

                </el-form-item>
                <el-form-item label="未中奖用户赠送优惠券">
                    <el-button style="max-width:200px;" type="primary" @click="couponToogle">
                        选择优惠券
                    </el-button>
                    <p class="form-help">可以添加最多一个优惠券</p>
                    <choose-coupon ref="chooseCoupon" :config="chooseCouponConfig" :changeEvt="filtersCouponChange"></choose-coupon>
                    <el-table class="coupon-table" v-if="formFormatData.formData.coupon_id !=''" :data="formFormatData.formData.coupon" style="width: 50%;margin-top:20px;">
                        <el-table-column prop="date" label="优惠券名称">
                            <template slot-scope="scope">
                                <!-- {{coupon_name}} -->
                                <p>{{scope.row.coupon_name}}</p>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <div class="operation-group">
                                    <el-button class="wlm-text" type="text" @click="toggleSelection">删除</el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>
            </el-form>
        </div>
    </div>

    <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
        <el-button size="small" @click="saveForm" type="primary" :loading="butt">保存</el-button>
        <router-link tag="span" to="/application/blessingBag">
            <el-button size="small">返回</el-button>
        </router-link>
    </div>
</div>
</template>

<script>
import {
    praiseSave,
    praiseDetail
} from '@/api/operation'
import {
    getUserTag,
    couponList,
    blessingSave,
    blessingDetail
} from '@/api/application'
import {
    servicesList,
    shopIndex
} from '@/api/merchant'

import ChooseGoods from '@/components/ChooseGoods/index'
import ChooseFiles from '@/components/ChooseFiles/index'
import ChooseCoupon from '@/components/ChooseCoupon/index'
import ueditor from '@/components/Ueditor/index'
import {
    Base64
} from 'js-base64'
import {
    businessIndex
} from '@/api/merchant'
import mixins from '@/mixins/mixins'
export default {
    mixins: [mixins.getters('Form'), mixins.getters('Table')],
    components: {
        ChooseGoods,
        ChooseFiles,
        ChooseCoupon,
        ueditor
    },
    created() {
        this.$nextTick(() => {
            this.communitybtn()
            this.luckcrowdbtn()
            this.coupontableList()
            if (this.$route.query.blessing_id) {
                this.praiseDetailbtn()
            }
            

        })
    },
    data() {
        return {
            status:'',
            hx_time:[],
            chooseShangJia: '选择商家',
            color1: '#eeeeee',
            loading: false,
            butt: false,
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7
                }
            },
            lastID: -1,
            options: [],
            selectValue: [],
            isFirst: false,
            ueditorList: [],
            coupon_name: [{}],
            defaultMsg1: '',
            currentRow: [],
            $lineIndex: -1,
            formType: '1',
            dialogListVisible: false,
            couponTypeList: [],
            // 选择商品参数
            chooseGoodsConfig: {
                type: ['chooseGoods'],
                model: 'normal',
                unique: false,
                thumbtn: 'thumbtns',
                initList: [],
            },
            //背景音乐
            choosePlatmaginConfig: {
                type: ['audio'],
                model: 'display',
                uploadConfig: {
                    limit: 1,
                    isMore: true,
                    model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'audio',
                bindKey: {
                    key: 'blessing_music',
                    model: 'img'
                }
            },
            //活动封面图
            choosePlatformConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                    limit: 1,
                    isMore: true,
                    model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                    key: 'blessing_img',
                    model: 'img'
                }
            },
            choosePlatsappConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                    limit: 1,
                    isMore: true,
                    model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                    key: 'blessing_sapp_img',
                    model: 'img'
                }
            },
            choosePlatwechatConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                    limit: 1,
                    isMore: true,
                    model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                    key: 'blessing_wechat_img',
                    model: 'img'
                }
            },
            chooseimgJp: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                    limit: 1,
                    isMore: true,
                    model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                    key: 'prize_image',
                    model: 'img'
                }
            },
            chooseCouponConfig: {
                type: ['chooseCoupon'],
                model: 'display',
                get_limit_type: 0,
                disabled: [{
                        label: 'status',
                        value: 1,
                        reverse: true
                    },
                    {
                        label: 'get_limit_type',
                        value: 1
                    }, {
                        label: 'coupon_type',
                        value: 40
                    }
                ],
                initList: []
            },
            tableFormatData: {
                current: 'userTable',
                userTable: {
                    key: 'userTable',
                    api: {
                        getList: businessIndex
                    },
                    tableData: [],
                    periods: [],
                    files: {
                        name: '',
                        bus_id: '',
                        ids: [],
                        checkall: '0',
                        Recycle: '1',
                        praise_id: this.$route.query.blessing_id ? this.$route.query.blessing_id : ''
                    },
                    pagination: {
                        page: 1,
                        list_rows: 10,
                        pagesizes: [10, 20, 50],
                        total: 0
                    }
                }
            },
            formFormatData: {
                key: ['basicset', 'active'],
                api: {
                    editForm: {
                        api: blessingDetail,
                        params: {
                            blessing_id: ''
                        },
                        redirect: 'blessing_id',
                        filters: {
                            img: {
                                bindInit: ['chooseimgJp', 'choosePlatformConfig', 'choosePlatsappConfig', 'choosePlatwechatConfig', 'choosePlatmaginConfig']
                            },
                            choose: {
                                bindInit: ['chooseGoodsConfig']
                            },

                        },
                    },
                    //   submitForm:praiseSave
                },
                formData: {
                    background_color: '#FCDD31',
                    blessing_wechat_text: '',
                    is_false_look: 2,
                    false_look_rand: 0,
                    is_false_forward: 2,
                    false_look_num: '',
                    false_forward_rand: 0,
                    prize_price: '',
                    false_user_num: '',
                    false_forward_num: '',
                    coupon_name: '',
                    blessing_img: [],
                    prize_image: [],
                    coupon_id: "",
                    coupon: [{
                        coupon_id: '',
                        coupon_name: ''
                    }],
                    blessing_wechat_img: [],
                    blessing_sapp_img: [],
                    blessing_music: [],
                    title: '', //活动名称
                    time: [], //活动时间
                    source: [], //活动渠道
                    is_subscribe: 2, //是否强制关注公众号 1是 2否
                    user_group: 1, //抽奖人群
                    label: [], //用户标签选项
                    label_ids: [],
                    community: [], // 选中的社群ID
                    content: '', //活动内容
                    is_coupon: 2, //1开启 2关闭
                    address: '',
                    blessing_rule:'',
                    praise_number: '',
                    type: 1, //奖品模式 1名次 2 点赞
                    rank: '', //前几名可以获奖
                    SelectTabs: [], //标签设置选择的标签
                    goods: [], //选中的商品信息
                    is_self_close: 0,
                    draw_count_day: '',
                    is_win_user_draw: 2,
                    share_draw_count: '',
                    share_draw_impose: '',
                    prize: {
                        prize_num: '',
                        prize_hx_time_over: 1,
                        prize_hx_time: '',
                        hx_start_time: '',
                        hx_end_time: '',
                        image: [],
                        bus_id: '',
                        store_ids: [],
                        title: ''
                    },
                },
                rules: {
                    title: [{
                        message: '请填写活动名称',
                        required: true,
                        trigger: 'change',

                    }],
                }
            }
        }
    },
    computed: {
        // $coupon_name() {
        //     return this.formFormatData.formData.coupon_name
        // },
    },
    mounted() {
        this.$nextTick(() => {
            setTimeout(() => {
                this.isFirst = true
            }, 500)

        })
    },
    methods: {
        toggleSelection() {
            this.formFormatData.formData.coupon_id = ''
            this.coupon_name = []
             this.formFormatData.formData.coupon[0].coupon_id=''
            this.formFormatData.formData.coupon[0].coupon_name = ''

        },
        //添加优惠券
        filtersCouponChange(arg) {
            const {
                displayData
            } = arg
            const data = displayData[0]
            console.log(displayData[0], '122144')

            this.formFormatData.formData.coupon_id = data.coupon_id
            this.formFormatData.formData.coupon_name = data.name
            this.formFormatData.formData.coupon[0].coupon_id = data.coupon_id
            this.formFormatData.formData.coupon[0].coupon_name = data.name
            // this.coupon_name[0].name = data.name

            //  this.formFormatData.formData.coupon_name = displayData.map(item=>{item.id})
        },
        couponToogle() {
            this.$refs.chooseCoupon.toggle()
            
        },
        praiseDetailbtn() {
            this.loading = true
            this.butt = true
            blessingDetail({
                blessing_id: this.$route.query.blessing_id
            }).then(res => {
                console.log("res++++++++++++++++++++++", res.data.data)
                if (res.data.code == 1) {
                    this.hx_time= res.data.data.prize.hx_time
                    this.formFormatData.formData = res.data.data
                    this.chooseShangJia = res.data.data.prize.business_name
                    this.defaultMsg1 = res.data.data.content
                    this.status = res.data.data.status
                    this.loading = false
                    this.butt = false
                }
            })
        },
        //请求优惠券接口
        coupontableList() {
            couponList().then(res => {
                console.log("9888888888888888", this.formFormatData.formData, res.data.data.data)
                this.couponTypeList = res.data.data.data
                this.couponTypeList.forEach(item => {
                    this.formFormatData.formData.coupon.forEach((value1) => {
                        if (item.coupon_id == value1.coupon_id) {
                            this.coupon_name[0].name = item.name
                        }
                    })
                })

            })
        },
        deleteGiftTable(scope) {
            if (this.$route.query.status == 1) {
                this.$confirm('正在进行中的活动删除奖品后会对参与的用户造成影响?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.formFormatData.formData.prize.splice(scope.$index, 1)
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            } else {
                this.formFormatData.formData.prize.splice(scope.$index, 1)
            }
        },
        storeChange(val) {
            this.formFormatData.formData.prize.store_ids = val
            console.log(val, this.formFormatData.formData.prize, '12345')
        },
        showDialogSetDoor() {
            this.formType = '2'
            this.tableFormatData.userTable.files.bus_id = this.formFormatData.formData.prize.bus_id
            this.tableFormatData.userTable.api.getList = shopIndex
            this.filesSerch()
            this.dialogListVisible = true
        },
        clearData() {
            this.lastID = -1
        },
        tableRowClassName({
            row,
            rowIndex
        }) {
            if (row.storenum === 0) {
                return 'disable-row'
            }
            return ''
        },
        merchantRowClick(row) {
            console.log("fdffssss+++++++++++6666666666",row)
            if (this.lastID !== row.id) {
                this.lastID = row.id
                if (row.storenum === 0) {
                    console.log('22')
                    this.$message({
                        message: '该商家没有门店~',
                        type: 'warning'
                    })
                } else {
                    this.chooseShangJia = row.name;
                    this.formFormatData.formData.prize.bus_id = row.id
                    // const tableItem = this.formFormatData.formData.prize[this.$lineIndex]
                    // tableItem['business_name'] = row.name
                    // tableItem['store_ids'] = []
                    // this.formFormatData.formData.prize.splice(this.$lineIndex, 1, tableItem)
                }
            }
        },
        showDialogSet(data) {
            this.$lineIndex = data
            this.formType = '1'
            this.tableFormatData.userTable.api.getList = businessIndex
            this.formFormatData.formData.prize.store_ids=[]
            this.filesSerch()
            this.dialogListVisible = true
        },
        //删除标签设置数据
        delbtn(scope) {
            if (this.$route.query.status == 1) {
                this.$confirm('正在进行中的活动删除标签后会对参与的用户造成影响?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.formFormatData.formData.label.splice(scope.$index, 1)
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            } else {
                this.formFormatData.formData.label.splice(scope.$index, 1)
            }
        },
        shopInfoChange(msg) {
            this.defaultMsg1 = msg
        },
        formFormatCallBack(data, type, response) {
            if (type === 'editForm') {
                const {
                    content
                } = data
                this.defaultMsg1 = content
            }
        },
        //请求社群接口
        communitybtn() {
            servicesList({
                list_rows: 'all'
            }).then(res => {
                this.selectValue = res.data.data
            })
        },
        // 点击标签用户请求接口
        luckcrowdbtn() {
            getUserTag().then(res => {
                const {
                    data: {
                        data: msgData = []
                    }
                } = res
                this.options = msgData
            })
        },
        //控制商品弹出框的显示
        goodsToogle() {
            this.$refs.chooseGoods.toggle()
        },
        //   构造商品信息
        filtersChange(val) {
            this.currentRow = val.currentRow
            const displayData = val.displayData
            const result = []
            displayData.map(item => {
                const newData = {
                    image: [{
                        file_path: item.image[0]['file_path']
                    }],
                    goods_name: item.goods_name,
                    goods_id: item.goods_id,
                    stock_num: item.stock,
                    goods_price: item.goods_min_price
                }
                result.push({
                    goods: newData,
                    goods_id: item.goods_id
                })
            })
            this.formFormatData.formData.goods = result
        },
        //  删除选中的商品
        deleteTable(scope) {
            this.formFormatData.formData.goods.splice(scope.$index, 1)
            this.currentRow.splice(scope.$index, 1)
        },
        // 点击图片出现弹窗
        uploadChange({
            displayData = []
        }) {
            this.formFormatData.formData.prize[this.$index].image = displayData
        },
        uploadColumn(index) {
            this.$index = index
            this.$refs.chooseFiles.toggle()
        },
        rankingbtn($event, scopedata) {
            if (!$event) {
                console.log("ddddaaaaaaaaaaaaadffffffffffff", $event, scopedata)
            }
            console.log("ddddaaaaaaaaaaaaadffffffffffff", $event, scopedata)
        },
        addGiftTable() {
            if (this.formFormatData.formData.type == 1) {
                this.formFormatData.formData.prize.push({
                    bus_id: '',
                    store_ids: [],
                    business_name: '',
                    image: '',
                    prize_hx_time_over: 1,
                    prize_hx_time: '',
                    title: '',
                    ranking: ''
                })
            } else if (this.formFormatData.formData.type == 2) {
                this.formFormatData.formData.prize.push({
                    bus_id: '',
                    open_overlay: '',
                    store_ids: [],
                    business_name: '',
                    prize_hx_time_over: 1,
                    prize_hx_time: '',
                    image: '',
                    title: '',
                    like_num: ''
                })
            }
        },
        //点击保存按钮
        saveForm() {
            // 在保存之前判断是否必填
           if (this.formFormatData.formData.title == '') {
                this.$message.error('请输入活动名称！')
                return
            }
            if (this.formFormatData.formData.time == '') {
                this.$message.error('请输入活动时间！')
                return
            }
             if (this.formFormatData.formData.source.length == 0) {
                this.$message.error('请选择活动渠道！')
                return
            }
            if (this.formFormatData.formData.blessing_img.length == 0) {
                this.$message.error('请选择活动主图！')
                return
            }
             if (this.formFormatData.formData.blessing_sapp_img.length == 0) {
                this.$message.error('请选择小程序分享图！')
                return
            }
             if (this.formFormatData.formData.blessing_wechat_img.length == 0) {
                this.$message.error('请选择公众号分享图！')
                return
            }
            if (this.formFormatData.formData.blessing_wechat_text.length == 0) {
                this.$message.error('请选择分享描述！')
                return
            }
            if (this.formFormatData.formData.user_group==5 && this.formFormatData.formData.address=='') {
                this.$message.error('请输入地区信息！')
                return
            }
            if (this.formFormatData.formData.user_group==6 && this.formFormatData.formData.label_ids=='') {
                this.$message.error('请选择标签用户！')
                return
            }
            if (this.formFormatData.formData.draw_count_day == '') {
                this.$message.error('请输入用户每天抽奖次数！')
                return
            }
             if (this.formFormatData.formData.share_draw_count == '') {
                this.$message.error('请输入分享可得抽奖次数！')
                return
            }
            if (this.formFormatData.formData.share_draw_impose == '') {
                this.$message.error('请输入每天分享最多得抽奖次数！')
                return
            }
            if (this.formFormatData.formData.prize.title == '') {
                this.$message.error('请输入奖品名称！')
                return
            }
            if (this.formFormatData.formData.prize_price == '') {
                this.$message.error('请输入奖品价值！')
                return
            }
            if (this.formFormatData.formData.prize.prize_num == '') {
                this.$message.error('请输入奖品数量！')
                return
            }
            if (this.formFormatData.formData.prize_image.length == 0) {
                this.$message.error('请输入奖品图片！')
                return
            }
            if (this.formFormatData.formData.prize.prize_hx_time_over == 3 && !this.hx_time) {
                this.$message.error('请选择奖品核销有效期！')
                return
            }
            if (this.formFormatData.formData.prize.store_ids.length == 0) {
                this.$message.error('请选择核销门店！')
                return
            }
            
            //奖品核销时间
            if(this.formFormatData.formData.prize.prize_hx_time_over == 3 && !!this.hx_time){
                console.log('this.hx_time',this.hx_time);
                this.formFormatData.formData.prize.hx_start_time = this.hx_time[0];
                this.formFormatData.formData.prize.hx_end_time = this.hx_time[1];
            }
            
            //   富文本赋值
            this.formFormatData.formData.content = this.defaultMsg1
            if (this.formFormatData.formData.coupon_id != '') {
                this.formFormatData.formData.is_coupon = 1;
                this.formFormatData.formData.coupon = [{
                    'coupon_id':this.formFormatData.formData.coupon_id,
                    'coupon_name':this.formFormatData.formData.coupon_name
                }]
            } else {
                // this.formFormatData.formData.is_coupon = 2;
                //  coupon: [{
                //         coupon_id: '',
                //         coupon_name: ''
                //     }],
                this.formFormatData.formData.coupon=[{
                        coupon_id: '',
                        coupon_name: ''
                    }]
            }
            console.log("分段函数发金卡戴珊",this.formFormatData.formData)

            // return
            const data = Base64.encode(JSON.stringify(this.formFormatData.formData))

            console.log("ssssssssssssss+++++++++++++++++++++", this.formFormatData.formData)
            if(this.status!=3){
                 blessingSave({
                    data
                }).then(res => {
                    const {
                        data: {
                            code,
                            msg
                        }
                    } = res
                    if (code == 1) {
                        this.butt = false
                        this.$message({
                            type: 'success',
                            message: '保存成功!'
                        })
                        this.$router.push('/application/blessingBag')
                    } else {
                        this.butt = false
                        this.$message.error(msg)
                    }
                }).finally(() => {
                    this.butt = false
                })
            }else{
                this.$message.error("已结束的活动无法保存！")
                return
            }
            
        },
    },
}
</script>

<style lang="scss" scoped>
$update: 50px;

.update-load {
    display: inline-block;
    cursor: pointer;
    width: $update;
    height: $update;
    background: #fafbff;
    border: 1px dashed #c0ccda;
    color: #a8abb0;
    border-radius: 5px;

    i {
        font-size: 14px;
        color: #8c939d;
        width: $update;
        height: $update;
        line-height: $update;
        text-align: center;
    }

    .el-select-dropdown {
        max-width: 243px;
    }

    .el-select-dropdown__item {
        display: inline-block;
    }

    .el-select-dropdown__item span {
        min-width: 205px;
        display: inline-block;
    }
}
</style>
